package hhh.app.presenter.ui.view;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.RelativeLayout;

import hhh.app.R;

/**
 * Created by Administrator on 2017/1/5 0005.
 */
public class SortView extends RelativeLayout {
    private ListView sortList;
    private ArrayAdapter<String> sortAdapter;

    private String[] data={"默认","价格","销量"};
    private String[] coldata={ "default","price","quantity"};
    private int sid=0;

    public void setOnSelectListener(OnSelectListener onSelectListener) {
        this.onSelectListener = onSelectListener;
    }

    private OnSelectListener onSelectListener;

    public SortView(Context context) {
        super(context);
        init();
    }

    public SortView(Context context, AttributeSet attrs) {
        super(context, attrs);
        init();
    }

    public SortView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init();
    }

    private void init() {
        LayoutInflater.from(getContext()).inflate(R.layout.view_sort,this,true);
        sortList= (ListView) findViewById(R.id.sort_list);
        sortAdapter=new ArrayAdapter<String>(getContext(),android.R.layout.simple_list_item_1,data);

        sortList.setAdapter(sortAdapter);
        sortList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                if(sid!=i){
                    sid=i;
                    if(onSelectListener!=null){
                        onSelectListener.onSelectListener(coldata[sid]);
                    }
                }
            }
        });
    }

    public String getShowText(){
        return data[sid];
    }

    public String getColString() {
        return coldata[sid];
    }

    public interface OnSelectListener{
        public void onSelectListener(String val);
    }
}
